package com.guaoran.interview.spring.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Map;

/**
 * @author : 孤傲然
 * @description : ${random} 随机值
 * @date :2020/1/8 14:21
 */
@RestController
@ConfigurationProperties(prefix = "my")
@PropertySource(value = "classpath:test.properties",ignoreResourceNotFound = false)
/**
 * SpringApplication从application.properties以下位置的文件加载属性并将其添加到Spring中Environment：
 一个/config当前目录的子目录
 当前目录
 类路径/config包
 类路径根
 */
@Configuration(proxyBeanMethods = false)
public class RandomController {
    private Map random;
    private Map dataSize;

    @Autowired
    private Environment environment;

    public Map getRandom() {
        return random;
    }

    public void setRandom(Map random) {
        this.random = random;
    }

    public Map getDataSize() {
        return dataSize;
    }

    public void setDataSize(Map dataSize) {
        this.dataSize = dataSize;
    }

    @GetMapping("random")
    public Map get(){
        return random;
    }


    @GetMapping("environment/{key}")
    public String getEnvironment(@PathVariable String key){
        return environment.getProperty(key);
    }


    @GetMapping("dataSize")
    public String getDateSize(){
        System.out.println(dataSize);
        return "dataSize";
    }
}
